<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #operationBeforeExtend="{ record }">
        <a-link @click="handleItem(record)">明细</a-link>
      </template>
    </ma-crud>
    <a-drawer :footer="false" :width="1400" v-model:visible="visible" @cancel="visible = false">
      <template #title> 成本明细 </template>
      <settleDetail v-if="visible"  :itemData="itemData" />
    </a-drawer>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import financialSettle from '@/api/financial/financialSettle'
import { Message } from '@arco-design/web-vue'
import settleDetail from "@/views/financial/settleDetail/index.vue"
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()
const visible = ref(false)
const itemData = ref({})
const handleItem = (row)=>{
  visible.value = true
  itemData.value = row
}


const options = reactive({
  id: 'flyos_financial_settle',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: financialSettle.getList,
  recycleApi: financialSettle.getRecycleList,
  add: {
    show: true,
    api: financialSettle.save,
    auth: ['financial:settle:save']
  },
  edit: {
    show: true,
    api: financialSettle.update,
    auth: ['financial:settle:update']
  },
  delete: {
    show: true,
    api: financialSettle.deletes,
    auth: ['financial:settle:delete'],
    realApi: financialSettle.realDeletes,
    realAuth: ['financial:settle:realDeletes']
  },
  recovery: {
    show: true,
    api: financialSettle.recoverys,
    auth: ['financial:settle:recovery']
  },
  import: {
    show: true,
    url: 'financial/settle/import',
    templateUrl: 'financial/settle/downloadTemplate',
    auth: ['financial:settle:import']
  },
  export: {
    show: true,
    url: 'financial/settle/export',
    auth: ['financial:settle:export']
  }
})

const columns = reactive([
  {
    title: "结算单号",
    dataIndex: "order_no",
    formType: "input",
    search: true
  },
  {
    title: "结算类型",
    dataIndex: "type",
    formType: "select",
    search: true,
    dict: {
      data: [
        {
          label: "配送费",
          value: "1"
        },
        {
          label: "装卸费",
          value: "2"
        },
        {
          label: "铁路清算",
          value: "3"
        }
      ],
      translation: true
    }
  },
  {
    title: "税额",
    dataIndex: "tax_price",
    formType: "input",
    search: true
  },
  {
    title: "不含税金额",
    dataIndex: "no_tax_price",
    formType: "input",
    search: true
  },
  {
    title: "含税金额",
    dataIndex: "price",
    formType: "input",
    search: true
  },
  {
    title: "收款方",
    dataIndex: "send_dept_id",
    formType: "select",
    search: true,
    dict: {
      // 远程通用接口请求，新版代码生成都有一个 remote 接口
      remote: "system/dept/remote",
      // 指定组件接收的props
      props: { label: "name", value: "id" },
      // 开启分页
      openPage: false,
      // 远程请求配置项
      remoteOption: {
        // 按用户名排序
        sort: { id: "desc" }, // 如果不指定排序方式，默认为正序排序
        // 设置查询的字段
        select: ["id", "name"],
        // 设置数据过滤
        filter: {
          status: ['=',1]
        },
        // 关联模型
        relations: [],
      },
      translation: true
    },
  },
  {
    title: "业务所属月份",
    dataIndex: "month",
    formType: "date",
    search: true,
    showTime: false
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
])
</script>
<script> export default { name: 'financial:settle' } </script>